package com.woniuxy.oa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.oa.entity.Overtime;
import com.woniuxy.oa.entity.PageBean;
import com.woniuxy.oa.mapper.OvertimeMapper;
import com.woniuxy.oa.service.OvertimeService;

@Service("overtimeService")
public class OvertimeServiceImpl implements OvertimeService{
	
	@Autowired
	OvertimeMapper overtimeMapper;
	
	public void setOvertimeMapper(OvertimeMapper overtimeMapper) {
		this.overtimeMapper = overtimeMapper;
	}

	@Override
	public Integer addOvertimeInfo(Overtime overtime) {
		Integer result = overtimeMapper.insertOvertimeInfo(overtime);
		System.out.println(result);
		return result;
	}

	@Override
	public Integer modifyOvertimeInfo(Overtime overtime) {
		Integer re = overtimeMapper.updateOvertimeInfo(overtime);
		return re;
	}

	@Override
	public Integer removeOvertimeInfoByOm_id(Integer om_id) {
		Integer re = overtimeMapper.deleteOvertimeInfoByOm_id(om_id);
		return re;
	}

	@Override
	public Integer getOvertimeInfoByTotalPageRecored(Overtime overtime) {
		Integer totalRecord = overtimeMapper.selectOvertimeInfoByTotalPageRecored(overtime);
		return totalRecord;
	}

	@Override
	public PageBean<Overtime> getOvertimeInfoByNameAndPage(int pageIndex, int pageSize, Overtime overtime) {
		//查询总记录条数
		Integer totalRecord = overtimeMapper.selectOvertimeInfoByTotalPageRecored(overtime );
		System.out.println("总记录条数为："+totalRecord);
		
		List<Overtime> overtimeInfos = overtimeMapper.selectOvertimeInfoByNameAndPage((pageIndex-1)*pageSize, pageSize, overtime);
		System.out.println("每一页展示的客户信息：\n"+overtimeInfos);
		
		//封装分页数据
		PageBean<Overtime> pageBean = new PageBean<Overtime>();
		pageBean.setBeanList(overtimeInfos);
		pageBean.setPageIndex(pageIndex);
		pageBean.setPageSize(pageSize);
		pageBean.setTotalRecord(totalRecord);
		pageBean.setPageBeginAndPageEnd();
		System.out.println("封装分页数据：\n"+pageBean);
		return pageBean;
	}

}
